package net.bithappens.hnqe.scratchpad;

import java.net.URI;

import net.bithappens.hnqe.graph.EntryValue;
import net.bithappens.hnqe.impl.cache.query.SPARQLQuery;
import net.bithappens.hnqe.query.AtomConstant;
import net.bithappens.hnqe.query.ConstraintCompare;
import net.bithappens.hnqe.query.ConstraintMath;
import net.bithappens.hnqe.query.ConstraintMath.MathCompare;
import net.bithappens.hnqe.query.ConstraintMath.MathOperation;
import net.bithappens.hnqe.query.Link;
import net.bithappens.hnqe.query.Link.MatchType;
import net.bithappens.hnqe.query.Constraint;
import net.bithappens.hnqe.query.LogicalOperation;
import net.bithappens.hnqe.query.QueryFactory;
import net.bithappens.hnqe.query.QueryTree;
import net.bithappens.hnqe.query.Relation;
import net.bithappens.hnqe.query.ValueNode;
import net.bithappens.hnqe.query.ConstraintCompare.ConstraintType;
import net.bithappens.hnqe.query.Node;

public class TestRDFQueryBuilder {

	
	public static void main(String[] args) throws Exception {
		
//		Node node = new Node("NODETYPE", "N1", null); 
//		ValueNode valNode = new ValueNode("V1", null, new EntryValue(10));
//		
//		ConstraintCompare compare = new ConstraintCompare(node.getProperty("somePropery"), ConstraintType.EQUAL, new AtomValue(new EntryValue("text")));
//		
//		ConstraintMath compareMath = new ConstraintMath(valNode.getValueAttribute(), MathCompare.EQUAL);
//		compareMath.addCalcStep(MathOperation.ADD, new AtomValue(new EntryValue(10)));
//		
//		
//		Relation rel1 = new Relation(null, "R1", new URI("http://someURI"));
//		Link link1 = new Link(MatchType.ANYCONNECTION, rel1, node, valNode);
//		
//		Relation rel2 = new Relation("RELTYPE", "R2", new URI("http://someURI"));
//		Link link2 = new Link(MatchType.EXACTMATCH, rel1, node, valNode);
//		
//		QueryTree query = LogicalOperation.AND(
//				LogicalOperation.OR(compare, compareMath),
//				LogicalOperation.OR(link1, link2)
//			);
		
		
		
		QueryFactory factory = new QueryFactory();
		
		Node bob = factory.newNode("person");
		Node alice = factory.newNode("person");
		
		Relation someRelation = factory.newRelation();
		Link relatives = QueryFactory.ANYCONNECTION(someRelation, bob, alice);
		
		
		ConstraintMath ageCompare = QueryFactory.MATH_EQUAL(bob.getProperty("age"));
		
		ageCompare.addCalcStep(MathOperation.ADD, alice.getProperty("age"));
		ageCompare.addCalcStep(MathOperation.ADD, QueryFactory.newConstant(5));
		
		Constraint name = QueryFactory.EQUAL(bob.getProperty("name"), QueryFactory.newConstant("bob"));
		
		QueryTree rootQueryTree = QueryFactory.AND(ageCompare, name, relatives);
		

		
	}
	
	
}
